<?php

header("Content-type: text/xml\n\n");
echo ( '<?xml version="1.0"?>' . "\n");
?>


<?php

session_start();

include '../datos/AccesoDatos.php';
include 'session.php';
include_once ('sqlinjection.php');
if (isset($_GET['accion'])) {
    $accion = $_GET['accion'];
}





$objPersona = new Persona();
switch ($accion) {
 
    case "centrosmedicos": $objPersona->ListarEmpleadoCentroMedico();
         break;
     
     case "especialidades": $objPersona->ListarEmpleadoEspecialidades();
         break;
     
     case "secresxmedico": $objPersona->ListarSecretariasEmpleado();
         break;
     
     case "empleadoxsecre": $objPersona->ListarEmpleadosSecretaria();
         break;
     
}

class Persona {

    var $dtresultados = array();
    var $idpersona;
    var $idcentromedico;


    public function ListarEmpleadoCentroMedico() {


        $page = $_GET['page'];

// get how many rows we want to have into the grid - rowNum parameter in the grid 
        $limit = $_GET['rows'];

// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel 
        $sidx = $_GET['sidx'];

// sorting order - at first time sortorder 
        $sord = $_GET['sord'];
        
       $this->idpersona =$_SESSION['IdPersona'];
       

        // $this->idpersona = $_GET['idpersona'];

        $sql = "pa_ListarPersonasCentroMedico('".$this->idpersona ;
        $objDatos = new AccesoDatos();
        $objDatos->ejecutarConsulta($sql);

        $count = $objDatos->devuelveRegsLeidos();
        // calculate the total pages for the query 
        if ($count > 0 && $limit > 0) {
            $total_pages = ceil($count / $limit);
        } else {
            $total_pages = 0;
        }

// if for some reasons the requested page is greater than the total 
// set the requested page to total page 
        if ($page > $total_pages)
            $page = $total_pages;

// calculate the starting position of the rows 
        $start = $limit * $page - $limit;

// if for some reasons start position is negative set it to 0 
// typical case is that the user type 0 for the requested page 
        if ($start < 0)
            $start = 0;

        $s = '<rows>';
        $s .='<page>' . $page . '</page>';
        $s .= '<total>' . $total_pages . "</total>";
        $s .='<records>' . $count . '</records>';
           
$cont = 0;

        while ($row = $objDatos->devuelveArreglo()) {
            
            if($cont>=$start)
            {
           $s .= '<row id="' . $row['ID_PERSONAJURIDICA'] . '">';
           $s .= '<cell><![CDATA[' . $row['DS_EMPRESA'] . ']]></cell>';
           $s .= '<cell><![CDATA[""]]></cell>';
           $s .= '<cell><![CDATA[' . $row['DS_INTERVALOCONSULTA'] . ']]></cell>';
           $s .= '<cell><![CDATA[""]]></cell>';
           $s .= '<cell><![CDATA[' . $row['DS_LUNES'] . ']]></cell>';
           $s .= '<cell><![CDATA[""]]></cell>';
           $s .= '<cell><![CDATA[' . $row['DS_MARTES'] . ']]></cell>';
           $s .= '<cell><![CDATA[""]]></cell>';
           $s .= '<cell><![CDATA[' . $row['DS_MIERCOLES'] . ']]></cell>';
           $s .= '<cell><![CDATA[""]]></cell>';
           $s .= '<cell><![CDATA[' . $row['DS_JUEVES'] . ']]></cell>';
           $s .= '<cell><![CDATA[""]]></cell>';
           $s .= '<cell><![CDATA[' . $row['DS_VIERNES'] . ']]></cell>';
           $s .= '<cell><![CDATA[""]]></cell>';
           $s .= '<cell><![CDATA[' . $row['DS_SABADO'] . ']]></cell>';
           $s .= '<cell><![CDATA[""]]></cell>';
           $s .= '<cell><![CDATA[' . $row['DS_DOMINGO'] . ']]></cell>';
           $s .= '<cell><![CDATA[' . $row['VL_CONSULTA'] . ']]></cell>';
          
            $s .= '</row>';
            }
            
            $cont++;
            
                  }
$s .='</rows>';
echo $s;

    }
    
       public function ListarEmpleadoEspecialidades() {


        $page = $_GET['page'];

// get how many rows we want to have into the grid - rowNum parameter in the grid 
        $limit = $_GET['rows'];

// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel 
        $sidx = $_GET['sidx'];

// sorting order - at first time sortorder 
        $sord = $_GET['sord'];
        
       $this->idpersona = $_SESSION['IdPersona'];
       
       $centromedico = $_GET['centromedico'];

        // $this->idpersona = $_GET['idpersona'];

        $sql = "pa_ListarEspecialidadesEmpleado('".$this->idpersona . "','" . $centromedico;
        $objDatos = new AccesoDatos();
        $objDatos->ejecutarConsulta($sql);

        $count = $objDatos->devuelveRegsLeidos();
        // calculate the total pages for the query 
        if ($count > 0 && $limit > 0) {
            $total_pages = ceil($count / $limit);
        } else {
            $total_pages = 0;
        }

// if for some reasons the requested page is greater than the total 
// set the requested page to total page 
        if ($page > $total_pages)
            $page = $total_pages;

// calculate the starting position of the rows 
        $start = $limit * $page - $limit;

// if for some reasons start position is negative set it to 0 
// typical case is that the user type 0 for the requested page 
        if ($start < 0)
            $start = 0;

        $s = '<rows>';
        $s .='<page>' . $page . '</page>';
        $s .= '<total>' . $total_pages . "</total>";
        $s .='<records>' . $count . '</records>';
           
$cont = 0;

        while ($row = $objDatos->devuelveArreglo()) {
            
            if($cont>=$start)
            {
           $s .= '<row id="' . $row['ID_ESPECIALIDADMEDICOS'] . '">';
           $s .= '<cell><![CDATA[' . $row['DS_ESPECIALIDADMEDICOS'] . ']]></cell>';
          
            $s .= '</row>';
            }
            
            $cont++;
            
                  }
$s .='</rows>';
echo $s;

    }
    
    
    public function ListarSecretariasEmpleado() {


        $page = $_GET['page'];

// get how many rows we want to have into the grid - rowNum parameter in the grid 
        $limit = $_GET['rows'];

// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel 
        $sidx = $_GET['sidx'];

// sorting order - at first time sortorder 
        $sord = $_GET['sord'];
        
       $this->idpersona = $_SESSION['IdPersona'];
       

        // $this->idpersona = $_GET['idpersona'];

        $sql = "pa_ListarSecresXEmpleado('".$this->idpersona ;
        $objDatos = new AccesoDatos();
        $objDatos->ejecutarConsulta($sql);

        $count = $objDatos->devuelveRegsLeidos();
        // calculate the total pages for the query 
        if ($count > 0 && $limit > 0) {
            $total_pages = ceil($count / $limit);
        } else {
            $total_pages = 0;
        }

// if for some reasons the requested page is greater than the total 
// set the requested page to total page 
        if ($page > $total_pages)
            $page = $total_pages;

// calculate the starting position of the rows 
        $start = $limit * $page - $limit;

// if for some reasons start position is negative set it to 0 
// typical case is that the user type 0 for the requested page 
        if ($start < 0)
            $start = 0;

        $s = '<rows>';
        $s .='<page>' . $page . '</page>';
        $s .= '<total>' . $total_pages . "</total>";
        $s .='<records>' . $count . '</records>';
           
$cont = 0;
$id=0;


        while ($row = $objDatos->devuelveArreglo()) {
            
            if($cont>=$start)
            {
           $s .= '<row id="' .  $id .  '">';
           $s .= '<cell><![CDATA[' . $row['ID_PERSONA'] . '-' . $row['ID_PERSONASECRETARIA'] .  '-' . $row['ID_PERSONAJURIDICA'] . ']]></cell>';
           $s .= '<cell><![CDATA[' . $row['DS_EMPRESA'] . ']]></cell>';
           $s .= '<cell><![CDATA[' . $row['DS_NOMBRE'] .' ' .  $row['DS_APELLIDO1'] .' '.  $row['DS_APELLIDO2'] .  ']]></cell>';
          
            $s .= '</row>';
            }
              $id++;
            $cont++;
            
                  }
$s .='</rows>';
echo $s;

    }
    
 
    

     public function ListarEmpleadosSecretaria() {


        $page = $_GET['page'];

// get how many rows we want to have into the grid - rowNum parameter in the grid 
        $limit = $_GET['rows'];

// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel 
        $sidx = $_GET['sidx'];

// sorting order - at first time sortorder 
        $sord = $_GET['sord'];
        
       $this->idpersona = $_SESSION['IdPersona'];
       

        // $this->idpersona = $_GET['idpersona'];

        $sql = "pa_ListarEmpleadoxSecre('".$this->idpersona ;
        $objDatos = new AccesoDatos();
        $objDatos->ejecutarConsulta($sql);

        $count = $objDatos->devuelveRegsLeidos();
        // calculate the total pages for the query 
        if ($count > 0 && $limit > 0) {
            $total_pages = ceil($count / $limit);
        } else {
            $total_pages = 0;
        }

// if for some reasons the requested page is greater than the total 
// set the requested page to total page 
        if ($page > $total_pages)
            $page = $total_pages;

// calculate the starting position of the rows 
        $start = $limit * $page - $limit;

// if for some reasons start position is negative set it to 0 
// typical case is that the user type 0 for the requested page 
        if ($start < 0)
            $start = 0;

        $s = '<rows>';
        $s .='<page>' . $page . '</page>';
        $s .= '<total>' . $total_pages . "</total>";
        $s .='<records>' . $count . '</records>';
           
$cont = 0;
$id=0;

        while ($row = $objDatos->devuelveArreglo()) {
            
            if($cont>=$start)
            {
           $s .= '<row id="' .  $id.  '">';
           $s .= '<cell><![CDATA[' . $row['ID_PERSONA'] . '-' . $row['ID_PERSONASECRETARIA'] .  '-' . $row['ID_PERSONAJURIDICA'] . ']]></cell>';
           $s .= '<cell><![CDATA[' . $row['DS_EMPRESA'] . ']]></cell>';
           $s .= '<cell><![CDATA[' . $row['DS_NOMBRE'] .' ' .  $row['DS_APELLIDO1'] .' '.  $row['DS_APELLIDO2'] .  ']]></cell>';
          
            $s .= '</row>';
            }
            $id++;
            $cont++;
            
                  }
$s .='</rows>';
echo $s;

    }
    
 
}
?>

